import query from '@dfeidao/atom-nodejs/db/query';
import log from '@dfeidao/atom-nodejs/logger/log';
import { productid, systemid } from '../../atom/config';
import time from '../../atom/get_data';

interface Message {
	train_number: string;
}


// 表名	train_plan
// 标题	培训计划
// 字段名称	字段标题	字段类型	字段长度	是否为空	是否主键
// _id	id	string	50	ⅹ	√
// productid	产品ID	string	50	√	ⅹ
// train_number	培训编号	string	32	√	ⅹ
// training_name	培训名称	string	64	√	ⅹ
// lecturer_number	讲师编号	string	32	√	ⅹ
// lecturer_name	讲师姓名	string	16	√	ⅹ
// train_start_time	培训开始时间	timestamp	50	√	ⅹ
// training_time	培训结束时间	timestamp	50	√	ⅹ
// training_location	培训地点	string	64	√	ⅹ
// training_content	培训内容	string	512	√	ⅹ
// to_state	进行状态	int	16	√	ⅹ
// take_effect	是否生效	int	16	√	ⅹ
// supposed_come_peo_num	应到人数	int	32	√	ⅹ
// attendance	实到人数	int	32	√	ⅹ
// training_conclusion	培训结论	string	256	√	ⅹ
// 培训名称;”

// “讲师编号;”

// “讲师姓名;”

// “培训开始时间;”，“培训时间;”前一个框;

// “培训结束时间;”，“培训时间;”后一个框;

// “培训地点;”

// “培训内容概要;”

// “进行状态;”

// “是否生效;”
export default async function atom(msg: Message, action_id: string, session_id: string) {
	log(`Service begin`);
	const { exec, prepare } = await query(action_id, session_id, systemid);
	prepare('train_plan', ['train_number', 'training_name', 'lecturer_number', 'lecturer_name', 'train_start_time', 'training_time', 'training_location', 'training_content', 'to_state', 'take_effect'], { 'train_number': msg.train_number }, 1, 1, [], []);
	const { exec: e, prepare: p } = await query(action_id, session_id, systemid);
	p('training_objects', ['train_number', 'safety_department_no', 'safety_department_name'], { 'train_number': msg.train_number }, 1, 1, [], []);
	const [ress] = await exec();
	const [res1] = await e();
	const res = ress.map((v) => {
		const c = time(productid, 'train_start_time', v);
		return time(productid, 'training_time', c);
	});
	log(`Service end`);
	return { res, res1 };
}
